package dwarffortess.web.research;

import java.io.File;

public class FileLayoutTools {
    private static String[] REQUIRED_SUBDIRS =  {"data","data/init","data/objects","data/save"};
    private static String[] REQUIRED_FILES =  {"data/objects/language_words"};

    public static boolean isDFDirectory(File file)  {
        if (!file.exists()) {
            return false;
        }
        if (!file.isDirectory()) {
            return false;
        }
        for (String required_name : REQUIRED_SUBDIRS) {
            File required_dir = new File(file, required_name);
            if (!required_dir.exists()) {
                return false;
            }
            if (!required_dir.isDirectory()) {
                return false;
            }
        }
        for (String required_name : REQUIRED_FILES) {
            File required_file = new File(file, required_name);
            if (!required_file.exists()) {
                return false;
            }
            if (required_file.isDirectory()) {
                return false;
            }
        }
        return true;
    }

    public static boolean isDFWorldDirectory(File file)  {
        if (!file.exists()) {
            return false;
        }
        if (!file.isDirectory()) {
            return false;
        }
        File worldDatFile = new File(file, "world.dat");
        if (!worldDatFile.exists()) {
            return false;
        }
        if (!worldDatFile.canRead()) {
            return false;
        }
        return true;
    }

}
